﻿namespace Socut
{
    using System;
    using System.Data;
    using System.Data.OleDb;
    using System.Data.SqlClient;

    internal class CParameter
    {
        public static void AccessParameters(string sql, string[,] para, OleDbCommand cmd, OleDbConnection ConnSql)
        {
            cmd.Connection = ConnSql;
            if (para != null)
            {
                for (int i = 0; i < para.GetLength(0); i++)
                {
                    cmd.Parameters.Add(new OleDbParameter(para[i, 0], NullToStr(para[i, 1])));
                }
            }
            cmd.CommandText = sql;
        }

        private static string NullToStr(string str)
        {
            if (str == null)
            {
                return "";
            }
            return str;
        }

        public static void SqlserverParameters(string sql, string[,] para, SqlCommand cmd, SqlConnection ConnSql)
        {
            sql = sql.Trim();
            cmd.Connection = ConnSql;
            if (sql.Trim().IndexOf(" ") < 0)
            {
                cmd.CommandType = CommandType.StoredProcedure;
            }
            if (para != null)
            {
                for (int i = 0; i < para.GetLength(0); i++)
                {
                    cmd.Parameters.Add(new SqlParameter(para[i, 0], NullToStr(para[i, 1])));
                }
            }
            cmd.CommandText = sql;
        }
    }
}

